package common

import (
	"familytree/conn"
	"fmt"

	"github.com/jinzhu/gorm"
)

//根据id号码更新
func UpdataInfo(db *gorm.DB, data Info) {

	tmp_bool := Isidexists(db, data.Id)
	if tmp_bool == false {
		fmt.Println("您不是家族成员，不可以更改信息!")
	} else {
		if data.Name != "" {
			err := db.Table("info").Where("id = ?", data.Id).Update("name", data.Name).Error
			conn.ErrCheck(err)
		}

		if data.Sex != "" {
			err := db.Table("info").Where("id = ?", data.Id).Update("sex", data.Sex).Error
			conn.ErrCheck(err)
		}

		if data.Introduce != "" {
			err := db.Table("info").Where("id = ?", data.Id).Update("introduce", data.Introduce).Error
			conn.ErrCheck(err)
		}

		if data.Age != "" {
			err := db.Table("info").Where("id = ?", data.Id).Update("age", data.Age).Error
			conn.ErrCheck(err)
		}

		if data.Password != "" {
			err := db.Table("info").Where("id = ?", data.Id).Update("password", data.Password).Error
			conn.ErrCheck(err)
		}
	}

}
